<template>
	<view class="service-page">
		<view class="result">
			<mescroll-uni ref="mescrollRef" @init="mescrollInit" @up="upCallback" :up="mescrolTop" :down="mescrolDown"
				:height="height" @down="downCallback">
				<view class="result-item" v-for="(item, index) in resultListDate" :key="'result-item-'+index"
					@click="handleServiceDetails(item)">
					<view class="title">
						<text>{{ item.title }}</text>
						<text class="mony">
							{{
								Number(item.price) === 0 ?
								'面议' :
								`${Number(item.price).toFixed(2)} 元`
							}}
						</text>
					</view>
					<view class="tag">
						<view class="lt">
							<view class="time">
								{{handleTimeStrToTimeStamp(item.at)}}
							</view>
							<view class="impo" v-if="item.isShowTag">
								明天
							</view>
							<view class="area" v-if="item.serv_addr">
								{{ item.serv_addr }}
							</view>
						</view>
						<!-- <view class="rt">
							<view class="distance">
								<uni-icons color="#22A366" type="paperplane-filled" size="12" />
								{{ item.distance }}
							</view>
						</view> -->
					</view>
					<view class="describe">
						<!-- <view class="tit">{{ item.stitle }}</view> -->
						<view class="details"> {{ item.content }} </view>
					</view>
					<view class="footer">
						<view class="end-time">
							<icon class="icon icon-time"></icon>
							{{
								handleTimeDifference(item.at, item.deadline) 
							}}
						</view>
						<!-- <view class="enroll">
							<icon class="icon icon-man"></icon> <text>{{ item.manNum }}</text>人参与
						</view> -->
					</view>
				</view>
			</mescroll-uni>
		</view>
	</view>
</template>


<script>
	import {
		getMyWorksheetCreated,
		getWorksheetNewest
	} from '@/utils/api.js';

	import {
		publics
	} from '@/mixins/publics.js';

	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";

	export default {
		mixins: [publics, MescrollMixin],
		props: {
			pageHeightIN: {
				type: Number,
				default: 0
			}
		},
		computed: {
			height() {
				const num = this.pageHeightIN - 36 - 75 - 10 - 15 - 15;
				return num + 'px';
			}
		},
		data() {
			return {
				mescrolTop: {
					use: true,
					page: {
						size: 10 // 每页数据的数量,默认10
					},
				},
				mescrolDown: {
					use: true,
					auto: false,
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					mustToTop: true
				},
				resultListDate: [],
				pageNum: 0,
				isNextPage: false
			}
		},
		mounted() {
			this.mescroll.triggerDownScroll();
		},
		methods: {
			// 详情
			handleServiceDetails(item) {
				uni.setStorageSync("workSheetDetails", item);
				uni.navigateTo({
					url: "/demandHallPages/service/serviceDetails"
				})
			},
			upCallback(page) {
				this.pageNum = page.num;
				this.pageSize = page.size;
				const postData = {
					pid: page.num, // 页码, 默认从1开始
					page_size: page.size,
				}
				this.getWorksheetNewestApi(postData)
			},

			reloadList() {
				this.mescroll.resetUpScroll();
			},

			getWorksheetNewestApi(postData) {
				getWorksheetNewest(postData).then(res => {
					if (res.code === 200) {
						if (res.data.worksheets >= postData.page_size && this.isNextPage) {
							this.resultListDate = this.resultListDate.concat(res.data.worksheets);
						} else {
							this.resultListDate = res.data.worksheets;
						}
						this.mescroll.endSuccess(this.resultListDate.length, this.isNextPage);
					} else {
						this.mescroll.endErr()
					}
				}).catch(data => {
					//  请求失败,隐藏加载状态
					this.mescroll.endErr()
				})
			},

			hanleIsNextPage() {
				let postData = {
					pid: this.pageNum += 1, // 页码, 默认从1开始
					page_size: this.pageSize
				}
				getMyWorksheetCreated(postData).then(res => {
					if (res.code === 200) {
						this.isNextPage = Boolean(res.data.worksheets.length);
					}
				})
			}
		}
	}
</script>


<style lang="scss">
	.service-page {
		width: 100%;
		height: 100%;
		position: relative;

		.result {
			width: 100%;
			height: 100%;

			&-item {
				margin: 0 10px 10px;
				background-color: #fff;
				padding: 16px 12px 0px;
				border-radius: 10px;

				.title {
					display: flex;
					justify-content: space-between;
					font-family: PingFangSC-SNaNpxibold;
					font-weight: 600;
					font-size: 17px;
					color: #1E1F23;
					margin-bottom: 8px;

					.mony {
						font-size: 15px;
						color: #F54D3B;
					}
				}

				.tag {
					overflow: hidden;
					margin-bottom: 12px;

					.time,
					.impo,
					.area {
						display: inline-block;
						padding: 3px 7px;
						background: #F7F6FB;
						border-radius: 4px;
						color: #55525F;
						margin-right: 6px;
						font-size: 12px;

						&.impo {
							background-color: #22A366;
							color: #fff;
						}
					}

					.distance {
						font-family: PingFangSC-Regular;
						font-weight: 400;
						font-size: 12px;
						color: #55525F;
						letter-spacing: -0.7px;
						line-height: 23px;
					}
				}

				.describe {
					background: #F5F6FA;
					border-radius: 8px;
					padding: 8px 10px;
					font-size: 12px;
					margin-bottom: 12px;

					.tit {
						font-weight: 400;
						color: #181818;
						margin-bottom: 5px;
						font-size: 12px;
					}

					.details {
						color: #9B9B9B;
					}
				}

				.footer {
					height: 42px;
					line-height: 42px;
					border-top: 1px solid #f5f6fa;
					font-size: 12px;
					color: #9B9B9B;
					display: flex;
					justify-content: space-between;

					.icon {
						width: 12px;
						height: 12px;

						&.icon-time {
							background: url("/static/images/icon/time.png") no-repeat 0px 0px;
							background-size: 100% 100%;
						}

						&.icon-man {
							background: url("/static/images/icon/man.png") no-repeat 0px 0px;
							background-size: 100% 100%;
						}
					}
				}
			}
		}
	}
</style>